package com.liangzhong.model.activity
{
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.activity.christmas.ChristmasVo;
	import com.liangzhong.model.activity.qzone.QzoneVo;
	import com.liangzhong.model.activity.vip.VipVo;
	import com.liangzhong.model.type.GoodsType;
	import com.liangzhong.model.type.OtherGoodType;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	/**
	 *活动数据管理器 
	 * @author Administrator
	 * 
	 */	
	public class ActivityDateManager extends EventDispatcher
	{
		/**
		 *黄钻信息 
		 */		
		public var qzoneVo :QzoneVo = new QzoneVo();
		/**
		 * 
		 *圣诞节信息 
		 */		
		public var christmasVo :ChristmasVo = new ChristmasVo();
		/**
		 *冲级领取信息 
		 */		
		public var rushLevelObj :Object;
		/**
		 * 首充奖励
		 *[[id ，类型，数量],[]] 
		 */		
		public var theFirstCharge:Array = [[27,GoodsType.OTHER,1],[7,GoodsType.ATTRIBUTE,1],[18,GoodsType.MATERIAL,1],
			[41,GoodsType.FOOTWEAR,1],[16,GoodsType.OTHER,2]];
		/**
		 *累积充值奖励 
		 * [id ，类型，数量],[]] 
		 */		
		public var Topupfeedback:Array = [[15,GoodsType.MATERIAL,1],[16,GoodsType.OTHER,1],
			[6,GoodsType.OTHER,1],[27,GoodsType.OTHER,1],[17,GoodsType.OTHER,1],
			[29,GoodsType.OTHER,1],[79,GoodsType.TEAMCLOTH,1]];
		private var _vip:Array;
		
		
		/**
		 *活动vip奖励 
		 */
		private var _activityVip:Array;
		
		/**
		 * 打折物品列表 
		 */
		public var timeLimitArr:Array;
		
		/**
		 *在线奖励时间 
		 */
		public var onlineTime:int;
		/**
		 *在线奖励类型 
		 */
		public var onlineType:int;
		public function ActivityDateManager(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		/**
		 *获取vip列表 
		 * @return 
		 * 
		 */		
		public function getVipList():Array
		{
			if(_vip == null)
			{
				_vip = new Array();
				var vo:VipVo;
				var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITY_VIP);
				
				var xmlList:XMLList = xml.children();
				var len:int = xmlList.length();
				for(var i:int = 0;i < len;i++)
				{
					vo = new VipVo();
					vo.analysisXml(xmlList[i]);
					_vip.push(vo);
				}
			}
			return _vip;
		}
		/**
		 *根据vip等级获取vipVo数据 
		 * @param $lv
		 * 
		 */
		public function getVipVoByVipLv($lv:int):VipVo	
		{
			getVipList();
			for each(var vo:VipVo in _vip)
			{
				if(vo.lv == $lv)
					return vo;
			}
			return null;
		}
		/**
		 * 解析活动vip奖励 
		 * 
		 */
		private function analysisActivityVip():void
		{
			if(_activityVip == null)
			{
				_activityVip = new Array();
				var vo:VipVo;
				var xml:XML = ResourceManager.instance.getResource(ResourceConst.FESTIVAL_VIP_XML);
				
				var xmlList:XMLList = xml.children();
				var len:int = xmlList.length();
				for(var i:int = 0;i < len;i++)
				{
					vo = new VipVo();
					vo.analysisActivityVip(xmlList[i]);
					_activityVip.push(vo);
				}
			}
		}
		/**
		 *根据vipID
		 * 取活动vipVo
		 * @param $lv
		 * @return 
		 * 
		 */
		public function getActivityVipVo($lv:int):VipVo
		{
			analysisActivityVip();
			for each(var vo:VipVo in _activityVip)
			{
				if(vo.lv == $lv)
					return vo;
			}
			return null;
		}
		/**
		 *获得打折活动信息（购买物品列表） 
		 * @param $arr
		 * 
		 */
		public function getActivityTimeLimitInfo($arr:Array):void
		{
			timeLimitArr = [];
			var vo:ActivityTimeLimitVo;
			for each(var obj:Object in $arr)
			{
				vo = new ActivityTimeLimitVo();
				vo.analysis(obj);
				timeLimitArr.push(vo);
			}
			
		}
		
		
		/**
		 *获得在线奖励信息 
		 * @param $obj
		 * 
		 */
		public function onLineInfo($type:int ,$time:int):void
		{
			onlineType = $type;
			onlineTime = onlineTimeByType($type) - $time;
			if(onlineTime <=0)
				onlineTime = 0;
		}
		/**
		 *在线奖励
		 * 1分钟   100声望  3W欧元
		 * 3分钟   100声望  5W欧元
		 * 10分钟  200声望  10W欧元
		 * 20分钟  250声望  15W欧元
		 * 35分钟  300声望  20W欧元
		 * 60分钟  350声望  30W欧元
		 * 90分钟  500声望  50W欧元 
		 * 
		 */
		public function setOnlineTime():void
		{
			
		}
		/**
		 *不同的类型需要的时间不同 
		 * @param $type 秒
		 * @return 
		 * 
		 */		
		private function onlineTimeByType($type:int):int
		{
			switch($type)
			{
				case 0:
					return 60;
				case 1:
					return 180;
				case 2:
					return 600;
				case 3:
					return 1200;
				case 4:
					return 2100;
				case 5:
					return 3600;
				case 6:
					return 5400;
			}
			return 0;
		}
		
		/**
		 *不同的类型需要的时间不同 
		 * @param $type 秒
		 * @return 
		 * 
		 */		
		public function onlineAwardByType():String
		{
			switch(onlineType)
			{
				case 0:
					return "100声望 ,3W欧元";
				case 1:
					return "100声望 ,5W欧元";
				case 2:
					return "200声望 ,10W欧元";
				case 3:
					return "250声望 ,15W欧元";
				case 4:
					return "300声望 ,20W欧元";
				case 5:
					return "350声望 ,30W欧元";
				case 6:
					return "500声望 ,50W欧元";
			}
			return "";
		}
		
	}
}